package lcr;

public class Test0073 {

    public static void main(String[] args) {
        Solution0073_1 solution = new Solution0073_1();
        int[] piles = {3,6,7,11};
        System.out.println(solution.minEatingSpeed(piles, 8));
    }

}

class Solution0073_1 {
    public int minEatingSpeed(int[] piles, int h) {
        int left = Integer.MAX_VALUE, right = Integer.MIN_VALUE;
        for (int pile : piles) {
            left = Math.min(left, pile);
            right = Math.max(right, pile);
        }

        while (left < right) {
            int mid = (left + right)>>1;

            int time = getTime(piles, mid);
            if (time <= h){
                right = mid;
            } else {
                left = mid + 1;
            }
        }

        return left;
    }

    private int getTime(int[] piles, int k) {
        int time = 0;
        for (int pile : piles) {
            time += (pile + k - 1) / k;
        }
        return time;
    }
}
